package mapred;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class AntBuilder {

    public static void buildXML(Class<?> cls) throws IOException {
        String className = cls.getSimpleName();
        String classPath = cls.getName();
        InputStream is = cls.getResourceAsStream("/build.xml");
        if (is == null) {
            is = new FileInputStream("build.xml");
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        new File("xml").mkdirs();
        BufferedWriter bw = new BufferedWriter(new FileWriter("xml/"
                + className + ".xml"));
        for (String line = br.readLine(); line != null; line = br.readLine()) {
            bw.write(line.replaceAll("@classname@", className).replaceAll(
                    "@classpath@", classPath));
            bw.newLine();
        }
        bw.flush();
        bw.close();
        br.close();
    }

}
